package vincent.com.layouttest;

import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import vincent.com.layouttest.view.HeadsetConnectStateView;
import vincent.com.layouttest.view.P2GainModeView;
import vincent.com.layouttest.view.P2LineoutModeView;
import vincent.com.layouttest.view.SystemVolumeLevelView;

/**
 * Created by zhengwenchen on 2016/5/9.
 */
public class SystemIconsActivity extends ColorStatusActivity {

    SystemVolumeLevelView volumeLevel;
    P2GainModeView gainModeView;
    P2LineoutModeView lineoutModeView;
    HeadsetConnectStateView headsetConnectStateView;

    @Override
    public View onCreateView(ViewGroup rootView) {
        return LayoutInflater.from(this).inflate(R.layout.p2_system_icons, rootView, true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        volumeLevel = (SystemVolumeLevelView)findViewById(R.id.system_volume_level);
        gainModeView = (P2GainModeView)findViewById(R.id.p2_gain_mode_view);
        lineoutModeView = (P2LineoutModeView)findViewById(R.id.p2_lineout_mode_view);
        headsetConnectStateView = (HeadsetConnectStateView)findViewById(R.id.p2_statusbar_headset);
    }

    @Override
    public String getToolbarTitle() {
        return "系统Icon";
    }

    public void setVolume(View v){
        volumeLevel.setVolume(240);
    }

    public void changeGain(View v){

        String current = gainModeView.getCurrentGainMode();
        Intent successIntent = new Intent(P2GainModeView.ACTION_CHANGE_GAIN_MODE_COMPLETED);
        if("0".equals(current)){
            successIntent.putExtra("current", "1");
        }else if("1".equals(current)){
            successIntent.putExtra("current", "2");
        }else if("2".equals(current)){
            successIntent.putExtra("current", "0");
        }else{
            successIntent.putExtra("current", "0");
        }

        sendBroadcast(successIntent);
    }

    public void changeLineout(View v){
        String current = lineoutModeView.getCurrentLineoutMode();
        Intent successIntent = new Intent(P2LineoutModeView.ACTION_CHANGE_LINEOUT_COMPLETED);
        if("1".equals(current)){
            successIntent.putExtra("current", "2");
        }else if("2".equals(current)){
            successIntent.putExtra("current", "1");
        }else{
            successIntent.putExtra("current", "1");
        }

        sendBroadcast(successIntent);
    }

    public void changeHeadsetConnectState(View v){
        int state = headsetConnectStateView.getConnectState();
        Intent successIntent = new Intent(HeadsetConnectStateView.KUGOU_INTENT_ACTION_HEADSET_STATE_CHANGE);

        if(1 == state){
            successIntent.putExtra(HeadsetConnectStateView.HEADSET, 0);
        }else{
            successIntent.putExtra(HeadsetConnectStateView.HEADSET, 1);
        }

        sendBroadcast(successIntent);
    }
}
